package com.xzjt.web.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzjt.common.utils.R;
import com.xzjt.web.annotation.SysLogAnnotation;
import com.xzjt.web.entity.SysRole;
import com.xzjt.web.entity.SysUser;
import com.xzjt.web.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户角色 前端控制器
 * </p>
 *
 * @author yuandong
 * @since 2021-10-12
 */
@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 分页查询
     * 如果前端没有传递参数，可以在这里使用defaultValue设置默认值
     *
     * @param pageNum
     * @param pageSize
     * @param sysRole
     * @return
     */
    @SysLogAnnotation("查询角色列表")
    @GetMapping("/selectList")
    public R<?> selectList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, SysRole sysRole) {

        PageHelper.startPage(pageNum, pageSize);

        QueryWrapper<SysRole> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(sysRole.getRoleName()), "role_name", sysRole.getRoleName());
        queryWrapper.like(StrUtil.isNotBlank(sysRole.getStatus()), "status", sysRole.getStatus());

        List<SysRole> roleList = sysRoleService.list(queryWrapper);
        PageInfo<SysRole> pageInfo = new PageInfo<>(roleList);


        return R.ok(pageInfo);
    }

}
